<template>
<view class="content">
	<view class="box" :style='{"minHeight":"100vh","width":"100%","padding":"48rpx 24rpx 24rpx","background":"url(http://codegen.caihongy.cn/20241029/932c0c9393644035bb5a4c03192cb848.jpg) no-repeat center top / cover,#fff","height":"auto"}'>
		<view :style='{"border":"2rpx solid #fff","padding":"24rpx 48rpx","margin":"240rpx 0 0","borderRadius":"20rpx","textAlign":"center","background":"rgba(255,255,255,.3)","display":"block","width":"100%","position":"relative","height":"auto"}'>
			<image :style='{"margin":"0 auto 24rpx auto","borderRadius":"8rpx","top":"-220rpx","left":"40%","display":"block","width":"160rpx","position":"absolute","height":"160rpx"}' src="http://codegen.caihongy.cn/20241029/0bf4804c0dfc44c380a901f86e773df3.png" mode="aspectFill"></image>
			<view :style='{"border":"0","margin":"0 0 24rpx 0","borderRadius":"20rpx","flexWrap":"wrap","background":"none","display":"flex","width":"calc(100% - 0px)","height":"auto"}' v-if="tableName=='user'" class="uni-form-item uni-column">
				<view :style='{"width":"100%","lineHeight":"80rpx","fontSize":"28rpx","minWidth":"180rpx","color":"#23baf7","textAlign":"left"}' class="label">用户账号：</view>
				<input :style='{"border":"2rpx solid #23baf7","padding":"0px 24rpx","margin":"0px","color":"rgb(0, 0, 0)","borderRadius":"20rpx","textAlign":"left","flex":"1","background":"rgba(255, 255, 255,.8)","fontSize":"28rpx","lineHeight":"80rpx","height":"80rpx"}'  v-model="ruleForm.useraccount"  type="text"  class="uni-input" name="" placeholder="用户账号" />
			</view>
			<view :style='{"border":"0","margin":"0 0 24rpx 0","borderRadius":"20rpx","flexWrap":"wrap","background":"none","display":"flex","width":"calc(100% - 0px)","height":"auto"}' v-if="tableName=='user'" class="uni-form-item uni-column">
				<view :style='{"width":"100%","lineHeight":"80rpx","fontSize":"28rpx","minWidth":"180rpx","color":"#23baf7","textAlign":"left"}' class="label">密码：</view>
				<input :style='{"border":"2rpx solid #23baf7","padding":"0px 24rpx","margin":"0px","color":"rgb(0, 0, 0)","borderRadius":"20rpx","textAlign":"left","flex":"1","background":"rgba(255, 255, 255,.8)","fontSize":"28rpx","lineHeight":"80rpx","height":"80rpx"}'  v-model="ruleForm.password" type="password"  class="uni-input" name="" placeholder="密码" />
			</view>
			<view :style='{"border":"0","margin":"0 0 24rpx 0","borderRadius":"20rpx","flexWrap":"wrap","background":"none","display":"flex","width":"calc(100% - 0px)","height":"auto"}' v-if="tableName=='user'" class="uni-form-item uni-column">
				<view :style='{"width":"100%","lineHeight":"80rpx","fontSize":"28rpx","minWidth":"180rpx","color":"#23baf7","textAlign":"left"}' class="label">确认密码：</view>
				<input :style='{"border":"2rpx solid #23baf7","padding":"0px 24rpx","margin":"0px","color":"rgb(0, 0, 0)","borderRadius":"20rpx","textAlign":"left","flex":"1","background":"rgba(255, 255, 255,.8)","fontSize":"28rpx","lineHeight":"80rpx","height":"80rpx"}' v-model="ruleForm.password2" type="password" class="uni-input" name="" placeholder="确认密码" />
			</view>
			<view :style='{"border":"0","margin":"0 0 24rpx 0","borderRadius":"20rpx","flexWrap":"wrap","background":"none","display":"flex","width":"calc(100% - 0px)","height":"auto"}' v-if="tableName=='user'" class="uni-form-item uni-column">
				<view :style='{"width":"100%","lineHeight":"80rpx","fontSize":"28rpx","minWidth":"180rpx","color":"#23baf7","textAlign":"left"}' class="label">用户姓名：</view>
				<input :style='{"border":"2rpx solid #23baf7","padding":"0px 24rpx","margin":"0px","color":"rgb(0, 0, 0)","borderRadius":"20rpx","textAlign":"left","flex":"1","background":"rgba(255, 255, 255,.8)","fontSize":"28rpx","lineHeight":"80rpx","height":"80rpx"}'  v-model="ruleForm.username"  type="text"  class="uni-input" name="" placeholder="用户姓名" />
			</view>
            <view :style='{"border":"0","margin":"0 0 24rpx 0","borderRadius":"20rpx","flexWrap":"wrap","background":"none","display":"flex","width":"calc(100% - 0px)","height":"auto"}' v-if="tableName=='user'" class="">
				<view :style='{"width":"100%","lineHeight":"80rpx","fontSize":"28rpx","minWidth":"180rpx","color":"#23baf7","textAlign":"left"}' class="label">性别：</view>
				<picker :style='{"border":"0","margin":"0 0 24rpx 0","borderRadius":"20rpx","flexWrap":"wrap","background":"none","display":"flex","width":"calc(100% - 0px)","height":"auto"}' v-if="tableName=='user'"  @change="usergenderChange" :value="usergenderIndex" :range="usergenderOptions">
					<view>
						<view :style='{"border":"2rpx solid #23baf7","padding":"0 20rpx","color":"#666","borderRadius":"20rpx","textAlign":"left","flex":"1","background":"rgba(255, 255, 255,.8)","fontSize":"28rpx","lineHeight":"80rpx","height":"80rpx"}' class="uni-input">{{ruleForm.gender?ruleForm.gender:"请选择性别"}}</view>
					</view>
				</picker>
			</view>
            <view :style='{"border":"0","margin":"0 0 24rpx 0","borderRadius":"20rpx","flexWrap":"wrap","background":"none","display":"flex","width":"calc(100% - 0px)","height":"auto"}' v-if="tableName=='user'" @tap="userheadportraitTap" class="">
				<view :style='{"width":"100%","lineHeight":"80rpx","fontSize":"28rpx","minWidth":"180rpx","color":"#23baf7","textAlign":"left"}' class="label">头像：</view>
				<image :style='{"width":"180rpx","margin":"0px 0 0","borderRadius":"16rpx","objectFit":"cover","display":"block","height":"120rpx"}' v-if="ruleForm.headportrait" class="avator" :src="baseUrl+ruleForm.headportrait" mode=""></image>
                <image :style='{"width":"180rpx","margin":"0px 0 0","borderRadius":"16rpx","objectFit":"cover","display":"block","height":"120rpx"}' v-else class="avator" src="../../static/gen/upload.png" mode=""></image>
            </view>
			<view :style='{"border":"0","margin":"0 0 24rpx 0","borderRadius":"20rpx","flexWrap":"wrap","background":"none","display":"flex","width":"calc(100% - 0px)","height":"auto"}' v-if="tableName=='user'" class="uni-form-item uni-column">
				<view :style='{"width":"100%","lineHeight":"80rpx","fontSize":"28rpx","minWidth":"180rpx","color":"#23baf7","textAlign":"left"}' class="label">手机：</view>
				<input :style='{"border":"2rpx solid #23baf7","padding":"0px 24rpx","margin":"0px","color":"rgb(0, 0, 0)","borderRadius":"20rpx","textAlign":"left","flex":"1","background":"rgba(255, 255, 255,.8)","fontSize":"28rpx","lineHeight":"80rpx","height":"80rpx"}' v-model="ruleForm.mobile" type="text" class="uni-input" name="" placeholder="手机号码" />
			</view>
			<view :style='{"border":"0","margin":"0 0 24rpx 0","flexWrap":"wrap","background":"none","display":"flex","width":"calc(100% - 0px)","height":"auto"}' v-if="tableName=='user' && true" class="uni-form-item uni-column">
				<view :style='{"width":"100%","lineHeight":"80rpx","fontSize":"28rpx","minWidth":"180rpx","color":"#23baf7","textAlign":"left"}' class="label">验证码：</view>
				<input :style='{"border":"2rpx solid #23baf7","padding":"0 24rpx","margin":"0","color":"rgb(0, 0, 0)","borderRadius":"20rpx 0 0 20rpx","textAlign":"left","background":"rgba(255, 255, 255,.8)","width":"calc(100% - 200rpx)","fontSize":"28rpx","lineHeight":"80rpx","height":"80rpx"}' v-model="smscode" type="text" class="uni-input" name="" placeholder="请输入短信验证码" />
				<button :style='{"border":"0px solid #ddd","padding":"0px","margin":"0px","alignItems":"center","borderRadius":"0 20rpx 20rpx 0","background":"#23baf7","borderWidth":"0px 0px 0px 0","display":"flex","width":"200rpx","lineHeight":"80rpx","justifyContent":"center","height":"80rpx"}' type="primary" v-if="isEndFlag" @tap="sendsmscode" class="bg-red">发送验证码</button>
				<button :style='{"border":"0px solid #ddd","padding":"0px","margin":"0px","alignItems":"center","borderRadius":"0 20rpx 20rpx 0","background":"#23baf7","borderWidth":"0px 0px 0px 0","display":"flex","width":"200rpx","lineHeight":"80rpx","justifyContent":"center","height":"80rpx"}' type="primary" v-if="!isEndFlag" disabled="disabled" class="bg-red">{{SecondToDate}}</button>
			</view>
			<view :style='{"border":"0","margin":"0 0 24rpx 0","borderRadius":"20rpx","flexWrap":"wrap","background":"none","display":"flex","width":"calc(100% - 0px)","height":"auto"}' v-if="tableName=='merchants'" class="uni-form-item uni-column">
				<view :style='{"width":"100%","lineHeight":"80rpx","fontSize":"28rpx","minWidth":"180rpx","color":"#23baf7","textAlign":"left"}' class="label">商家账号：</view>
				<input :style='{"border":"2rpx solid #23baf7","padding":"0px 24rpx","margin":"0px","color":"rgb(0, 0, 0)","borderRadius":"20rpx","textAlign":"left","flex":"1","background":"rgba(255, 255, 255,.8)","fontSize":"28rpx","lineHeight":"80rpx","height":"80rpx"}'  v-model="ruleForm.merchantaccount"  type="text"  class="uni-input" name="" placeholder="商家账号" />
			</view>
			<view :style='{"border":"0","margin":"0 0 24rpx 0","borderRadius":"20rpx","flexWrap":"wrap","background":"none","display":"flex","width":"calc(100% - 0px)","height":"auto"}' v-if="tableName=='merchants'" class="uni-form-item uni-column">
				<view :style='{"width":"100%","lineHeight":"80rpx","fontSize":"28rpx","minWidth":"180rpx","color":"#23baf7","textAlign":"left"}' class="label">密码：</view>
				<input :style='{"border":"2rpx solid #23baf7","padding":"0px 24rpx","margin":"0px","color":"rgb(0, 0, 0)","borderRadius":"20rpx","textAlign":"left","flex":"1","background":"rgba(255, 255, 255,.8)","fontSize":"28rpx","lineHeight":"80rpx","height":"80rpx"}'  v-model="ruleForm.password" type="password"  class="uni-input" name="" placeholder="密码" />
			</view>
			<view :style='{"border":"0","margin":"0 0 24rpx 0","borderRadius":"20rpx","flexWrap":"wrap","background":"none","display":"flex","width":"calc(100% - 0px)","height":"auto"}' v-if="tableName=='merchants'" class="uni-form-item uni-column">
				<view :style='{"width":"100%","lineHeight":"80rpx","fontSize":"28rpx","minWidth":"180rpx","color":"#23baf7","textAlign":"left"}' class="label">确认密码：</view>
				<input :style='{"border":"2rpx solid #23baf7","padding":"0px 24rpx","margin":"0px","color":"rgb(0, 0, 0)","borderRadius":"20rpx","textAlign":"left","flex":"1","background":"rgba(255, 255, 255,.8)","fontSize":"28rpx","lineHeight":"80rpx","height":"80rpx"}' v-model="ruleForm.password2" type="password" class="uni-input" name="" placeholder="确认密码" />
			</view>
			<view :style='{"border":"0","margin":"0 0 24rpx 0","borderRadius":"20rpx","flexWrap":"wrap","background":"none","display":"flex","width":"calc(100% - 0px)","height":"auto"}' v-if="tableName=='merchants'" class="uni-form-item uni-column">
				<view :style='{"width":"100%","lineHeight":"80rpx","fontSize":"28rpx","minWidth":"180rpx","color":"#23baf7","textAlign":"left"}' class="label">商家名称：</view>
				<input :style='{"border":"2rpx solid #23baf7","padding":"0px 24rpx","margin":"0px","color":"rgb(0, 0, 0)","borderRadius":"20rpx","textAlign":"left","flex":"1","background":"rgba(255, 255, 255,.8)","fontSize":"28rpx","lineHeight":"80rpx","height":"80rpx"}'  v-model="ruleForm.merchantname"  type="text"  class="uni-input" name="" placeholder="商家名称" />
			</view>
            <view :style='{"border":"0","margin":"0 0 24rpx 0","borderRadius":"20rpx","flexWrap":"wrap","background":"none","display":"flex","width":"calc(100% - 0px)","height":"auto"}' v-if="tableName=='merchants'" class="">
				<view :style='{"width":"100%","lineHeight":"80rpx","fontSize":"28rpx","minWidth":"180rpx","color":"#23baf7","textAlign":"left"}' class="label">性别：</view>
				<picker :style='{"border":"0","margin":"0 0 24rpx 0","borderRadius":"20rpx","flexWrap":"wrap","background":"none","display":"flex","width":"calc(100% - 0px)","height":"auto"}' v-if="tableName=='merchants'"  @change="merchantsgenderChange" :value="merchantsgenderIndex" :range="merchantsgenderOptions">
					<view>
						<view :style='{"border":"2rpx solid #23baf7","padding":"0 20rpx","color":"#666","borderRadius":"20rpx","textAlign":"left","flex":"1","background":"rgba(255, 255, 255,.8)","fontSize":"28rpx","lineHeight":"80rpx","height":"80rpx"}' class="uni-input">{{ruleForm.gender?ruleForm.gender:"请选择性别"}}</view>
					</view>
				</picker>
			</view>
            <view :style='{"border":"0","margin":"0 0 24rpx 0","borderRadius":"20rpx","flexWrap":"wrap","background":"none","display":"flex","width":"calc(100% - 0px)","height":"auto"}' v-if="tableName=='merchants'" @tap="merchantsheadportraitTap" class="">
				<view :style='{"width":"100%","lineHeight":"80rpx","fontSize":"28rpx","minWidth":"180rpx","color":"#23baf7","textAlign":"left"}' class="label">头像：</view>
				<image :style='{"width":"180rpx","margin":"0px 0 0","borderRadius":"16rpx","objectFit":"cover","display":"block","height":"120rpx"}' v-if="ruleForm.headportrait" class="avator" :src="baseUrl+ruleForm.headportrait" mode=""></image>
                <image :style='{"width":"180rpx","margin":"0px 0 0","borderRadius":"16rpx","objectFit":"cover","display":"block","height":"120rpx"}' v-else class="avator" src="../../static/gen/upload.png" mode=""></image>
            </view>
			<view :style='{"border":"0","margin":"0 0 24rpx 0","borderRadius":"20rpx","flexWrap":"wrap","background":"none","display":"flex","width":"calc(100% - 0px)","height":"auto"}' v-if="tableName=='merchants'" class="uni-form-item uni-column">
				<view :style='{"width":"100%","lineHeight":"80rpx","fontSize":"28rpx","minWidth":"180rpx","color":"#23baf7","textAlign":"left"}' class="label">联系电话：</view>
				<input :style='{"border":"2rpx solid #23baf7","padding":"0px 24rpx","margin":"0px","color":"rgb(0, 0, 0)","borderRadius":"20rpx","textAlign":"left","flex":"1","background":"rgba(255, 255, 255,.8)","fontSize":"28rpx","lineHeight":"80rpx","height":"80rpx"}'  v-model="ruleForm.contactphone"  type="text"  class="uni-input" name="" placeholder="联系电话" />
			</view>
			<button :style='{"border":"0","padding":"0 40rpx","margin":"24rpx auto","color":"rgb(255, 255, 255)","borderRadius":"20rpx","background":"#23baf7","display":"inline-block","width":"calc(100% - 0px)","lineHeight":"88rpx","fontSize":"36rpx","minWidth":"200rpx","height":"88rpx"}' class="btn-submit" @tap="register" type="primary">注册</button>
			
			<view class="idea1" :style='{"width":"100%","background":"red","display":"none","height":"80rpx"}'>idea1</view>
			<view class="idea2" :style='{"width":"100%","background":"red","display":"none","height":"80rpx"}'>idea2</view>
			<view class="idea3" :style='{"width":"100%","background":"red","display":"none","height":"80rpx"}'>idea3</view>
		</view>
	</view>
</view>
</template>

<script>
    import multipleSelect from "@/components/momo-multipleSelect/momo-multipleSelect";
	export default {
		data() {
			return {
                usergenderOptions: [],
                usergenderIndex: 0,
                merchantsgenderOptions: [],
                merchantsgenderIndex: 0,
				ruleForm: {
                useraccount: '',
                password: '',
                username: '',
                gender: '',
                headportrait: '',
                mobile: '',
                openid: '',
                nickname: '',
                avatarurl: '',
                merchantaccount: '',
                password: '',
                merchantname: '',
                gender: '',
                headportrait: '',
                contactphone: '',
                openid: '',
                nickname: '',
                avatarurl: '',
				},
				smscode: "",
				// 倒计时定时器
				inter: null,
				// 倒计时
				count: 10,
				//倒计时结束标识
				isEndFlag: true,
				tableName:""
			}
		},
        components: {
            multipleSelect
        },
        computed: {
            baseUrl() {
                return this.$base.url;
            },
			SecondToDate: function() {
				var time = this.count;
				time = parseInt(time) + "秒后重发";
				return time;
			}
        },
		async onLoad() {
			let res = [];
			let table = uni.getStorageSync("loginTable");
            this.tableName = table;

                        // 自定义下拉框值
			if(this.tableName=='user'){
                this.usergenderOptions = "男,女".split(',');
				this.ruleForm.gender=this.usergenderOptions[0]
			}
                        // 自定义下拉框值
			if(this.tableName=='merchants'){
                this.merchantsgenderOptions = "男,女".split(',');
				this.ruleForm.gender=this.merchantsgenderOptions[0]
			}
			
			this.styleChange()
		},
		methods: {
			// 发送邮箱验证码
			async sendsmscode(){
				if(!this.ruleForm.mobile){
					this.$utils.msg(`手机号码不能为空`);
					return
				}
				if(this.ruleForm.mobile&&(!this.$validate.isMobile(this.ruleForm.mobile))){
					this.$utils.msg(`请输入正常的手机格式`);
					return
				}
				if (this.count > 0) {
					this.isEndFlag = false;
					var _this = this;
					this.inter = setInterval(function() {
						_this.count = _this.count - 1;
						if (_this.count <= 0) {
							clearInterval(_this.inter);
							_this.count=60;
							_this.isEndFlag = true;
						}
					}, 1000);
				}
				let res = await this.$api.sendsms(`${this.tableName}`, this.ruleForm.mobile);
				if (res.code == 0) {
					this.$utils.msg(`发送成功`);
				} else {
					this.$utils.errMsg(`服务器异常，请稍后重试`);
					return;
				}
			},

            // 下拉变化
            usergenderChange(e) {
                    this.usergenderIndex = e.target.value
                    this.ruleForm.gender = this.usergenderOptions[this.usergenderIndex]
            },
            userheadportraitTap() {
                let _this = this;
                this.$api.upload(function(res) {
                    _this.ruleForm.headportrait = 'upload/' + res.file;
					_this.$forceUpdate();
                });
            },
            // 下拉变化
            merchantsgenderChange(e) {
                    this.merchantsgenderIndex = e.target.value
                    this.ruleForm.gender = this.merchantsgenderOptions[this.merchantsgenderIndex]
            },
            merchantsheadportraitTap() {
                let _this = this;
                this.$api.upload(function(res) {
                    _this.ruleForm.headportrait = 'upload/' + res.file;
					_this.$forceUpdate();
                });
            },

            toggleTab(str) {
                this.$refs[str].show();
            },

			styleChange() {
				this.$nextTick(()=>{
					// document.querySelectorAll('.uni-input .uni-input-input').forEach(el=>{
					//   el.style.backgroundColor = this.registerFrom.content.input.backgroundColor
					// })
				})
			},
			// 获取uuid
			getUUID () {
				return new Date().getTime();
			},
			// 注册
			async register() {
				
				if((!this.ruleForm.useraccount) && `user` == this.tableName){
					this.$utils.msg(`用户账号不能为空`);
					return
				}
				if((!this.ruleForm.password) && `user` == this.tableName){
					this.$utils.msg(`密码不能为空`);
					return
				}
                if(`user` == this.tableName && (this.ruleForm.mima!=this.ruleForm.mima2)){
                    this.$utils.msg(`两次密码输入不一致`);
                    return
                }
				if((!this.ruleForm.username) && `user` == this.tableName){
					this.$utils.msg(`用户姓名不能为空`);
					return
				}
				if(`user` == this.tableName && this.ruleForm.mobile&&(!this.$validate.isMobile(this.ruleForm.mobile))){
					this.$utils.msg(`手机号应输入手机格式`);
					return
				}
				if((!this.ruleForm.merchantaccount) && `merchants` == this.tableName){
					this.$utils.msg(`商家账号不能为空`);
					return
				}
				if((!this.ruleForm.password) && `merchants` == this.tableName){
					this.$utils.msg(`密码不能为空`);
					return
				}
                if(`merchants` == this.tableName && (this.ruleForm.mima!=this.ruleForm.mima2)){
                    this.$utils.msg(`两次密码输入不一致`);
                    return
                }
				if((!this.ruleForm.merchantname) && `merchants` == this.tableName){
					this.$utils.msg(`商家名称不能为空`);
					return
				}
				if(`merchants` == this.tableName && this.ruleForm.contactphone&&(!this.$validate.isMobile(this.ruleForm.contactphone))){
					this.$utils.msg(`联系电话应输入手机格式`);
					return
				}
				await this.$api.registerSms(`${this.tableName}`, this.ruleForm, this.smscode);
				this.$utils.msgBack('注册成功');;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		min-height: calc(100vh - 44px);
		box-sizing: border-box;
	}
</style>
